import 'package:aio/aio.dart';
import 'package:flutter/cupertino.dart';
import 'package:app/generated/app_strings.dart';
import 'package:app/src/utils/status_utils.dart';

import '../works_2023/report_loss_bean.dart';
import '../worksdo/material_requisition_bean.dart';

///集合合同审核等实体类；通用字段；
class SuperContractCopyInfo extends MaterialInfo {
  //fixme 列表传递给详情页的id;详情页提交的id；审核id;
  String? ReviewTypeId = "";

  //fixme 列表显示名称;如： 合同编号，订单编号等。
  String? ReviewTypeName = "";

  ///===========================================================================fixme 提成审核
  //主键ID;(ReviewTypeId)
  String? Id = "";

  //人员类型
  String? manType = "";

  //提成类型 需要注意的是只有70%提成和30%提成两种
  String? payType = "";

  //开始日期
  String? beginDatetime = "";

  //结束日期
  String? endDatetime = "";

  //姓名
  String? merchandiserSalesname = "";

  //收款金额
  String? amount1 = "";

  //提成金额
  String? amount2 = "";

  //结存金额
  String? amount3 = "";

  //上报金额
  String? amount4 = "";

  //上报人
  String? createrName = "";

  //上报日期
  String? createDateTime = "";

  //当前状态（基本都是“待审核”）
  String? curStatus = "";

  //当前业务流程ID
  String? currentWFId = "";
  String? CurrentWFId = "";

  // "YwxId": "N6016-1",
  // "YwxName": "提成审核（退回修改）",
  //当前流程ID;
  String? YwxId = "";

  ///判断提成审核是否为已退回状态；
  bool isN6016_1() {
    if (YwxId == "N6016-1") {
      return true;
    }
    return false;
  }

  //当前流程名称
  String? YwxName = "";

  String? page = "";

  String? Ids = "";

  ///fixme =====================================================================提成比例审核
  //申请人
  String? ApplyName = "";
  String? curWfId = "";

  //MerchandiserRoyaltyRate 客服提成
  String? MerchandiserRoyaltyRate = "";

  //SalesmanRoyaltyRate 业务提成；fixme
  String? SalesmanRoyaltyRate = "";

  /// 业务员ID(销售经理)
  String? SalesmanId = "";

  ///判断提成比例审核是否为发起状态（发起没有退回选项）
  bool isN4029() {
    //print("YwxId=====================${YwxId}");
    if (YwxId == "N4029") {
      return true;
    }
    return false;
  }

  ///fixme =====================================================================报损审核
  ///申请日期
  String? Applicationdatetime = "";
  String? _Applicationdatetime = null;

  String getApplicationdatetime() {
    //2021-06-29 0:00:00 => 2021-06-29
    if (StringUtils.isEmpty(_Applicationdatetime)) {
      if (StringUtils.isNotEmpty(Applicationdatetime)) {
        var _list = Applicationdatetime?.split(" ");
        if (_list != null && _list.length > 0) {
          _Applicationdatetime = _list[0];
        }
      }
    }
    return _Applicationdatetime ?? "";
  }

  ///申请人
  String? ApprovalName = "";
  String? Approval = "";

  ///发起人
  String? Creater = "";
  String? CreaterName = "";

  ///流程id
  String? CurrentWfId = "";

  ///图片证件
  List<LoseApplyPics>? LoseApplyPic = null;
  List<String>? _LoseApplyPic = null;

  //获取图片证件
  List<String>? getPics() {
    if (_LoseApplyPic != null && _LoseApplyPic!.length > 0) {
      return _LoseApplyPic;
    }
    if (LoseApplyPic != null && LoseApplyPic!.length > 0) {
      if (_LoseApplyPic == null) {
        _LoseApplyPic = [];
      }
      _LoseApplyPic?.clear();
      LoseApplyPic?.forEach((element) {
        if (element.Pic != null) {
          _LoseApplyPic?.add(element.Pic!);
        }
      });
    }
    return _LoseApplyPic;
  }

  ///fixme =====================================================================五金领用审核
  String? PickId = "";
  String? PickCode = "";
  String? GroupId = "";
  String? UserId = "";
  String? AddDate = "";
  String? SubmitDate = "";
  String? FactoryId = "";
  String? IsDel = "";
  String? Status = "";
  String? OutUserId = "";
  String? OutDate = "";
  String? ReturnInfo = "";
  String? ReviewId = "";
  String? picktype = "";
  String? WfId = "";
  String? CurWfId = "";
  String? Page = "";
  String? StatusName;
  String? SDate = "";
  String? EDate = "";
  String? UserPersonName = "";

  ///fixme =====================================================================运输合同审核
  String? LContractCode = ""; //运输合同号
  String? MaterialType = ""; //物料类型
  String? CarrierName = ""; //承运商
  String? CompanyName = ""; //采购公司；中文文本对应 CompanyName2
  String? CreaterDateTime =
      ""; //创建时间；中文文本对应：CreaterDateTime2；getCreaterDateTime()
  String? PersonName = ""; //创建人；中文文本对应 PersonName8
  String? status = "";
  String? NodeStatus = "";
  String? wfId = "";

  @override
  fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    super.fromJson(json); //fixme 先实现父类的
    ReviewTypeId = json["ReviewTypeId"]?.toString() ?? "";
    ReviewTypeName = json["ReviewTypeName"]?.toString() ?? "";

    ///===========================================================================fixme 提成审核
    Id = json['Id']?.toString() ?? "";
    manType = json['manType']?.toString() ?? "";
    payType = json['payType']?.toString() ?? "";
    beginDatetime = json['beginDatetime']?.toString() ?? "";
    endDatetime = json['endDatetime']?.toString() ?? "";
    merchandiserSalesname = json['merchandiserSalesname']?.toString() ?? "";
    amount1 = json['amount1']?.toString() ?? "";
    amount2 = json['amount2']?.toString() ?? "";
    amount3 = json['amount3']?.toString() ?? "";
    amount4 = json['amount4']?.toString() ?? "";
    createrName = json['createrName']?.toString() ?? "";
    createDateTime = json['createDateTime']?.toString() ?? "";
    curStatus = json['curStatus']?.toString() ?? "";
    currentWFId = json['currentWFId']?.toString() ?? "";
    CurrentWFId = json['CurrentWFId']?.toString() ?? "";
    if (StringUtils.isEmpty(currentWFId)) {
      currentWFId = CurrentWFId;
    }
    if (StringUtils.isEmpty(CurrentWFId)) {
      CurrentWFId = currentWFId;
    }
    YwxId = json['YwxId']?.toString() ?? "";
    YwxName = json['YwxName']?.toString() ?? "";
    page = json['page']?.toString() ?? "";
    Ids = json['Ids']?.toString() ?? "";

    ///===========================================================================fixme 提成比例审核
    ApplyName = json['ApplyName']?.toString() ?? "";
    curWfId = json['curWfId']?.toString() ?? "";
    SalesmanId = json['SalesmanId']?.toString() ?? "";
    MerchandiserRoyaltyRate = json['MerchandiserRoyaltyRate']?.toString() ?? "";
    SalesmanRoyaltyRate = json['SalesmanRoyaltyRate']?.toString() ?? "";

    ///=========================================================================fixme 报损审核
    Applicationdatetime = json['Applicationdatetime']?.toString() ?? "";
    ApprovalName = json['ApprovalName']?.toString() ?? "";
    Approval = json['Approval']?.toString() ?? "";
    Creater = json["Creater"]?.toString() ?? "";
    CreaterName = json["CreaterName"]?.toString() ?? "";
    LoseApplyPic = setGenericFromJson(
        json, 'LoseApplyPic', <LoseApplyPics>[], LoseApplyPics());
    CurrentWfId = json['CurrentWfId']?.toString() ?? "";

    ///=========================================================================fixme 五金领用审核
    PickId = json['PickId']?.toString() ?? "";
    PickCode = json['PickCode']?.toString() ?? "";
    GroupId = json['GroupId']?.toString() ?? "";
    UserId = json['UserId']?.toString() ?? "";
    AddDate = json['AddDate']?.toString() ?? "";
    SubmitDate = json['SubmitDate']?.toString() ?? "";
    FactoryId = json['FactoryId']?.toString() ?? "";
    IsDel = json['IsDel']?.toString() ?? "";
    Status = json['Status']?.toString() ?? "";
    OutUserId = json['OutUserId']?.toString() ?? "";
    OutDate = json['OutDate']?.toString() ?? "";
    ReturnInfo = json['ReturnInfo']?.toString() ?? "";
    ReviewId = json['ReviewId']?.toString() ?? "";
    picktype = json['picktype']?.toString() ?? "";
    WfId = json['WfId']?.toString() ?? "";
    CurWfId = json['WfId']?.toString() ?? "";
    Page = json['Page']?.toString() ?? "";
    StatusName = json['StatusName']?.toString() ?? "";
    SDate = json['SDate']?.toString() ?? "";
    EDate = json['EDate']?.toString() ?? "";
    UserPersonName = json['UserPersonName']?.toString() ?? "";

    ///=========================================================================fixme 运输合同审核
    LContractCode = json['LContractCode']?.toString() ?? "";
    MaterialType = json['MaterialType']?.toString() ?? "";
    CarrierName = json['CarrierName']?.toString() ?? "";
    CompanyName = json['CompanyName']?.toString() ?? "";
    CreaterDateTime = json['CreaterDateTime']?.toString() ?? "";
    PersonName = json['PersonName']?.toString() ?? "";
    Status = json['Status']?.toString() ?? "";
    status = json['status']?.toString() ?? "";
    if (StringUtils.isEmpty(status)) {
      status = Status;//fixme 防在小写的status没有值时，数据提交报错。
    }
    if (StringUtils.isEmpty(Status)) {
      Status = status;
    }
    NodeStatus = json['NodeStatus']?.toString() ?? "";
    wfId = json['wfId']?.toString() ?? "";
  }

  @override
  instance() {
    // TODO: implement instance
    return SuperContractCopyInfo();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    //var map = <String, dynamic>{};
    var map = super.toJson(); //fixme 先继承父类的
    map["ReviewTypeId"] = ReviewTypeId;
    map["ReviewTypeName"] = ReviewTypeName;

    ///===========================================================================fixme 提成审核
    map["Id"] = Id;
    map["manType"] = manType;
    map["payType"] = payType;
    map["beginDatetime"] = beginDatetime;
    map["endDatetime"] = endDatetime;
    map["merchandiserSalesname"] = merchandiserSalesname;
    map["amount1"] = amount1;
    map["amount2"] = amount2;
    map["amount3"] = amount3;
    map["amount4"] = amount4;
    map["createrName"] = createrName;
    map["createDateTime"] = createDateTime;
    map["curStatus"] = curStatus;
    map["currentWFId"] = currentWFId;
    map["CurrentWFId"] = CurrentWFId;
    map["YwxId"] = YwxId;
    map["YwxName"] = YwxName;
    map["page"] = page;
    map["Ids"] = page;

    ///===========================================================================fixme 提成比例审核
    map["ApplyName"] = ApplyName;
    map["curWfId"] = curWfId;
    map["SalesmanId"] = SalesmanId;
    map["MerchandiserRoyaltyRate"] = MerchandiserRoyaltyRate;
    map["SalesmanRoyaltyRate"] = SalesmanRoyaltyRate;

    ///=========================================================================fixme 报损审核
    map["Applicationdatetime"] = Applicationdatetime;
    map["ApprovalName"] = ApprovalName;
    map["Approval"] = Approval;
    map["Creater"] = Creater;
    map["CreaterName"] = CreaterName;
    map["LoseApplyPic"] = LoseApplyPic;
    map["CurrentWfId"] = CurrentWfId;

    ///=========================================================================fixme 五金领用审核
    map["PickId"] = PickId;
    map["PickCode"] = PickCode;
    map["GroupId"] = GroupId;
    map["UserId"] = UserId;
    map["AddDate"] = AddDate;
    map["SubmitDate"] = SubmitDate;
    map["FactoryId"] = FactoryId;
    map["IsDel"] = IsDel;
    map["Status"] = Status;
    map["OutUserId"] = OutUserId;
    map["OutDate"] = OutDate;
    map["ReturnInfo"] = ReturnInfo;
    map["ReviewId"] = ReviewId;
    map["picktype"] = picktype;
    map["WfId"] = WfId;
    map["Page"] = Page;
    map["StatusName"] = StatusName;
    map["SDate"] = SDate;
    map["EDate"] = EDate;
    map["UserPersonName"] = UserPersonName;

    ///=========================================================================fixme 运输合同审核
    map["LContractCode"] = LContractCode;
    map["MaterialType"] = MaterialType;
    map["CarrierName"] = CarrierName;
    map["CompanyName"] = CompanyName;
    map["CreaterDateTime"] = CreaterDateTime;
    map["PersonName"] = PersonName;
    map["status"] = status;
    map["NodeStatus"] = NodeStatus;
    map["wfId"] = wfId;
    return map;
  }
}
